package com.example.myapplication.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.myapplication.R;


/**
 * @author: rongfeng
 * @date: 2020/9/9
 * @description 靓号背景
 */
public class PrettyNumberView extends RelativeLayout {
    private View mView;
    private RelativeLayout rl_root;
    private TextView tv_pretty_number;
    private ImageView img_pretty_number_icon;

    public PrettyNumberView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mView = LayoutInflater.from(context).inflate(R.layout.view_pretty_number, this);
        rl_root = mView.findViewById(R.id.rl_root);
        tv_pretty_number = mView.findViewById(R.id.tv_pretty_number);
        img_pretty_number_icon = mView.findViewById(R.id.img_pretty_number_icon);
    }

    public void setData(String number) {
        int level = number.length();
        int resBg;
        int resColor;
        int resIcon;
        switch (level) {
            case 3:
                resBg = R.drawable.shape_pretty_number_1;
                resColor = R.color.pretty_number_1;
                resIcon = R.mipmap.xinxiliu_icon_liang1;
                break;
            case 4:
                resBg = R.drawable.shape_pretty_number_2;
                resColor = R.color.pretty_number_2;
                resIcon = R.mipmap.xinxiliu_icon_liang2;
                break;
            case 5:
                resBg = R.drawable.shape_pretty_number_3;
                resColor = R.color.pretty_number_3;
                resIcon = R.mipmap.xinxiliu_icon_liang3;
                break;
            case 6:
                resBg = R.drawable.shape_pretty_number_4;
                resColor = R.color.pretty_number_4;
                resIcon = R.mipmap.xinxiliu_icon_liang4;
                break;
            default:
                resBg = R.drawable.shape_pretty_number_4;
                resColor = R.color.pretty_number_4;
                resIcon = R.mipmap.xinxiliu_icon_liang4;
                break;
        }
        rl_root.setBackgroundResource(resBg);
        tv_pretty_number.setTextColor(resColor);
        img_pretty_number_icon.setImageResource(resIcon);

    }

    private float dp2px(float dp) {
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
    }
}

